
//
//  HHThemeImageView.m
//  ThemeChange
//
//  Created by 花花 on 2016/12/8.
//  Copyright © 2016年 花花. All rights reserved.
//

#import "ThemeImageView.h"

@implementation ThemeImageView

- (instancetype)init{

    return [self initWithFrame:CGRectZero];
}
- (instancetype)initWithFrame:(CGRect)frame{

    if (self =[ super initWithFrame:frame]) {
        [self setup];
    }
    return self;

}
- (instancetype)initWithImage:(UIImage *)image{

    if (self = [super initWithImage:image]) {

        [self setup];
    }
    
    return self;

}

-(void)setImageName:(NSString *)imageName{

    if (_imageName != imageName) {
        _imageName = [imageName copy];
        [self themeDidChange];
    }

}
-(void)awakeFromNib{

    [super awakeFromNib];
    
    [self setup];

}
- (void)setup{

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(themeDidChange) name:kThemeDidChangeNotification object:nil];
    

}
-(void)dealloc{

    [[ NSNotificationCenter defaultCenter]removeObserver:self];
}
-(void)themeDidChange{

    UIImage *imgage= [[ThemeManager shareManager]loadImageWithImgName:_imageName];
    self.image =[imgage resizableImageWithCapInsets:self.edgeEnsets resizingMode:UIImageResizingModeStretch];

}

@end
